home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Misc / Crossword / Source / Dictionary.h < prev    next >
Text File  |  1992-10-10  |  2KB  |  74 lines

  1. /*
  2.  
  3. File Dictionary.h
  4.  
  5. A dictionary is responsible for finding words that match a prespecified pattern.  Each dictionary is tied to a .xdict file that contains both words and index information.  The index allows fast retrieval of words that have a specific letter pattern: for example, all five letter words that have a "c" in the third position.
  6.  
  7. The index is embedded as links in the word lists.  Each word that matches a pattern is followed by a link to the next word that matches that same pattern.  Here is an example entry for the word "hound":
  8.  
  9.     hound    30  72  -1  146  15
  10.  
  11. The next word with pattern "h-----" is #30, the next one with pattern "-o----" is #72, etc.  The -1 in the third position indicates that "hound" is the last word that matches "--u--."  An index table stores the first word in the list that matches each pattern, as well as giving the total number of words that match it.
  12.  
  13. */
  14.  
  15. #import "Notifier.h"
  16. #import "FunctionCache.h"
  17.  
  18.  
  19. /* ————————————————————————————————————————————————————————————————————————————  */
  20.  
  21.  
  22. #define DEFAULTDICTIONARY        "/default.xdict"
  23.  
  24. #define LETTERS            26
  25. #define LAST            -1                //    — end of list mark
  26. #define MINLETTERS        3
  27. #define MAXLETTERS        21                //    — range of word lengths
  28.  
  29. #define WILDCARD        '?'
  30. #define WORD(p,i)        * (int *) [(p)  elementAt: (i)]
  31.  
  32.  
  33. /* ————————————————————————————————————————————————————————————————————————————  */
  34.  
  35.  
  36. typedef struct {
  37.                     int        first;
  38.                     int        n;
  39.     } linkHead;
  40.  
  41.  
  42. typedef struct {
  43.                     int            n;
  44.                     long        words;
  45.                     linkHead    linkTable [LETTERS][MAXLETTERS];
  46.     } indexEntry;
  47.  
  48.  
  49. typedef indexEntry        wordIndex [MAXLETTERS + 1];
  50.  
  51.  
  52. /* ————————————————————————————————————————————————————————————————————————————  */
  53.  
  54.  
  55. @interface Dictionary:Notifier
  56. {
  57.     FunctionCache    * cache;
  58.     NXStream        * file;
  59.     wordIndex        index;
  60. }
  61.  
  62. - init;
  63. - (wordIndex *) getIndex;
  64. - free;
  65. - create: sender;
  66. - use: sender;
  67. - useDictionary: (const char *) filename;
  68. - find: (char *) pattern;
  69. - find: (char *) pattern  changeAt: (int) i;
  70. - findWithoutCache: (char *) pattern;
  71. - limit: (id) match  toLetter: (char) c  at: (int) i  forLength: (int) n;
  72. - read: (char *) string  word: (int) i  forLength: (int) n;
  73.  
  74. @end